﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chaos.view.lobby
{
    /// <summary>
    /// Interaction logic for faction.xaml
    /// </summary>
    public partial class faction : UserControl
    {
        public faction()
        {
            InitializeComponent();
        }

        private void selectfaction_Click(object sender, RoutedEventArgs e)
        {
            network.gameclient c = System.Windows.Application.Current.FindResource("game_client") as network.gameclient;
            if (c != null)
            {
                messages.request_assign_faction msg = new messages.request_assign_faction();
                msg.User = Properties.Settings.Default.UserName;
                msg.Faction = factionname.Text;
                c.sendmessage(msg);
            }
        }

        private void lockfaction_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            network.gameclient c = System.Windows.Application.Current.FindResource("game_client") as network.gameclient;
            if (c != null)
            {
                messages.request_lock_faction msg = new messages.request_lock_faction();
                msg.Faction = factionname.Text;
                msg.Lock = lockfaction.SelectedIndex > 0;
                c.sendmessage(msg);
            }
        }

        private void factiongrid_Drop(object sender, DragEventArgs e)
        {
            network.gameclient c = System.Windows.Application.Current.FindResource("game_client") as network.gameclient;
            if (c != null)
            {
                DataObject d = e.Data as DataObject;
                model.player p = d.GetData(typeof(model.player)) as model.player; 
                if (p != null)
                {
                    messages.request_assign_faction msg = new messages.request_assign_faction();
                    msg.User = p.Name;
                    msg.Faction = factionname.Text;
                    c.sendmessage(msg);
                }
            }
        }
    }
}
